<template>
    <div>
        <a href='/'>返回首页</a>
        <h1>房号列表显示</h1>
        门店类型<select v-model="info.roomid">
            <option value="">请选择</option>
            <option v-for="a in lisr" :value="a.Id">{{ a.RoomName }}</option>
        </select>
        房型类型<select v-model="info.fxid">
            <option value="">请选择</option>
            <option v-for="a in fx" :value="a.Id">{{ a.FXName }}</option>
        </select>
        <input type="button" value="查询" @click="getlist">
        <table class="table table-bordered">
            <thead>
                <tr>
                    <td>Id</td>
                    <td>门店类型</td>
                    <td>房型类型</td>
                    <td>房间号</td>
                    <td>房号状态</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="a in data">
                    <td>{{ a.Id }}</td>
                    <td>{{ a.RoomName }}</td>
                    <td>{{ a.FXName }}</td>
                    <td>{{ a.FJH }}</td>
                    <td>{{ a.NumberState == true ? "上架" : "下架" }}</td>
                    <td><input type="button" v-if="a.NumberState == true ? '上架' : ''" value="下架"
                            @click="xgzt(a.Id, false)">
                        <input type="button" v-if="a.NumberState == false ? '下架' : ''" value="上架"
                            @click="xgzt(a.Id, true)">
                        <input type="button" value="删除" @click="del(a.Id)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios';
import moment from 'moment';
import { useRouter, useRoute } from 'vue-router';
const router = useRouter();
const route = useRoute();
let info: any = reactive({
    roomid: '',
    fxid: ''
})
let data: any = ref([])
let lisr: any = ref([])
let fx: any = ref([])
onMounted(() => {
    getlist();
    getMD();
    getFX();
})
//显示
const getlist = () => {
    axios({
        url: '/api/Num/NumShow',
        method: 'get',
        params: info
    })
        .then(res => {
            console.log(res);
            data.value = res.data
        })
        .catch(err => {
            console.log(err);

        })
}
//门店查询

const getMD = () => {
    axios({
        url: '/api/Num/Show',
        method: 'get'
    })
        .then(res => {
            console.log(res);
            lisr.value = res.data
        })
}
//房型查询
const getFX = () => {
    axios({
        url: '/api/Num/ShowFX',
        method: 'get'
    })
        .then(res => {
            console.log(res);
            fx.value = res.data
        })
}
//修改状态
const xgzt = (id: any, state: any) => {
    if (confirm("确认修改状态吗？"))
        axios({
            url: '/api/Num/XGZT',
            method: 'get',
            params: {
                id: id,
                state: state
            }
        })
            .then(res => {
                if (res.data > 0) {
                    alert('修改状态成功')
                    getlist();
                    return;
                }
                else {
                    alert('修改状态失败')
                    return;
                }
            })
            .catch(err => {
                console.log(err);

            })
}
//删除
const del = (id: any) => {
    if (confirm("确认删除吗？"))
        axios({
            url: '/api/Num/Delete',
            method: 'delete',
            params: { id: id }
        })
            .then(res => {
                if (res.data > 0) {
                    alert('删除成功')
                    getlist();
                    return;
                }
                else {
                    alert('删除失败')
                    return;
                }
            })
            .catch(err => {
                console.log(err);

            })
}
</script>

<style scoped></style>